﻿using System;
using NExplorer.Properties;

namespace NExplorer.Commands
{
	public class UpOneFolderCommand : CommandBase
	{
		private readonly IExplorerService _explorer;

		public UpOneFolderCommand()
			: base("Up One Folder", Resources.Up)
		{
			_explorer = ServiceManager.Explorer;
			_explorer.CurrentDirectoryChanged += SetEnabled;
			
            SetEnabled(null, null);
		}

		private void SetEnabled(object sender, EventArgs e)
		{
			Enabled = _explorer.CurrentDirectory != null && _explorer.CurrentDirectory.Parent != null;
		}

		public override void Execute()
		{
			_explorer.NavigateTo(_explorer.CurrentDirectory.Parent);
		}

        public override void Dispose()
        {
            base.Dispose();

            _explorer.CurrentDirectoryChanged -= SetEnabled;
        }
	}
}